var goods_num = 0
var page = 1
var limit = 8




const instance = axios.create({
    baseURL: 'http://47.119.134.71:8080/',
    headers: {
        'Content-Type': 'text/plain;charset=UTF-8'
    }
})





instance({
    method: 'get',
    url: 'api/goods/getNum',

}).then(res => {
    goods_num = res.data.data

    layui.use('laypage', function() {
        var laypage = layui.laypage;

        //执行一个laypage实例
        laypage.render({
            elem: 'test1',
            count: goods_num //数据总数，从服务端得到
                ,
            limit: 8,
            jump: function(obj, first) {
                //obj包含了当前分页的所有参数，比如：
                app.get_goods(obj.curr, obj.limit)
                    //首次不执行
                if (!first) {
                    //do something
                }
            }
        });
    });
}).catch(err => {
    console.log(err);
})






var app = new Vue({
    el: "#app",
    data: {
        goods: []
    },
    methods: {
        get_goods: function(page, limit) {


            instance({
                method: 'get',
                url: 'api/goods/getByPage?page=' + page + "&limit=" + limit,

            }).then(res => {
                this.goods = res.data.data
            }).catch(err => {
                console.log(err);
            })

        }
    },
    mounted: function() {
        this.get_goods(page, limit)
    }
})


//检查用户是否已经登录的组件
var app2 = new Vue({
    el: "#top",
    data: {
        user_id: -1,
        user_name: ''
    },
    methods: {

    },
    mounted: function() {
        instance({
            method: 'get',
            url: 'api/user/getIdBySession',

        }).then(res => {
            this.user_id = res.data.data.user_id
            this.user_name = res.data.data.user_name

        }).catch(err => {
            console.log(err);
        })
    }
})